package com.sh.data.engine.common.util.excel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import java.util.*;

/**
 * @author : fuchen
 * @date : 2021/12/23 15:04
 */
public class ExcelStringListener extends AnalysisEventListener {

    private List<List<String>> dataList = new LinkedList<>();

    @Override
    public void invoke(Object o, AnalysisContext analysisContext) {
        Map<Object, Object> stringMap = (HashMap<Object, Object>) o;
        List<String> itemList = new ArrayList<>();
        stringMap.forEach(
            (key, value) -> {
                if (value == null) {
                    itemList.add("");
                } else {
                    itemList.add(value.toString());
                }
            });
        dataList.add(itemList);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
    }

    public List<List<String>> getDataList() {
        return dataList;
    }
}
